package com.wc.acwing.思维.回文字符串;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/4/9 15:52
 * @description
 * https://www.acwing.com/problem/content/5999/
 */

public class Main {
    /**
     * 思路：
     * 将字符串分为 3 部分
     * A B C
     * A 左边仅包含 lqb 的
     * B 中间第一个不包含lqb以及右边第一个不包含lqb的
     * C 右边仅包含 lqb 的
     *
     * 需要满足 3 个条件
     * 判断 B 部分是否为回文
     * 判断A的长度是不是 > C的长度
     * 判断A 是否为 C的前缀镜像
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 1010;
    static char[] s;
    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            s = (" " + sc.next()).toCharArray();
            n = s.length - 1;
            int l = 1, r = n;
            while (l <= n && (s[l] == 'l' || s[l] == 'q' || s[l] == 'b')) l++;
            while (r >= 1 && (s[r] == 'l' || s[r] == 'q' || s[r] == 'b')) r--;
            if(check(l, r)) out.println("Yes");
            else out.println("No");
        }
        out.flush();
    }

    static boolean check(int l, int r) {
        // 判断是否存在 B
        if (l > n || r < 1) return true;
        // 判断 B 部分是否为回文
        for (int i = l, j = r; i < j; i++, j--) {
            if (s[i] != s[j]) return false;
        }
        // 判断A的长度是不是 > C的长度
        if (n - r  + 1 < l) return false;

        // 判断A 是否为 C的前缀镜像
        for (int i = l - 1, j = r + 1; i >= 1 && j <= n; i--, j++) {
            if (s[i] != s[j]) return false;
        }
        return true;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

